home *** CD-ROM | disk | FTP | other *** search
/ Carousel / CAROUSEL.cdr / mactosh / john / hc_xcmd_.hqx / Searchreplace XCMD v.2.0 / card_5956.txt < prev    next >
Text File  |  1989-09-12  |  2KB  |  62 lines

  1. -- card: 5956 from stack: in.0
  2. -- bmap block id: 12075
  3. -- flags: 4000
  4. -- background id: 11496
  5. -- name: 
  6.  
  7.  
  8. -- part 1 (button)
  9. -- low flags: 00
  10. -- high flags: A002
  11. -- rect: left=155 top=264 right=286 bottom=349
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 1
  15. -- font id: 0
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: See Searchreplace Scripts
  20. ----- HyperTalk script -----
  21. on mouseUp
  22.   edit the script of me
  23. end mouseUp
  24. --
  25. --
  26. --search script
  27. --
  28. on search findWhat,findMethod
  29.   global markedText,foundWorked
  30.   put space & findMethod & space into findMethod
  31.   put quote & findWhat & quote into finalFind
  32.   put "find" & findMethod & finalFind into findForm
  33.   send findForm
  34.   if the foundchunk is not empty then
  35.     put the foundchunk into markedtext
  36.     put true into foundWorked
  37.   else
  38.     put false into foundWorked
  39.   end if
  40. end search
  41. --
  42. --
  43. --replace script
  44. --
  45. on replace replaceString
  46.   global markedText,foundWorked
  47.   if foundWorked then
  48.     put quote & replacestring & quote into replaceWithWhole
  49.     put "put " &  replaceWithWhole  & " into "  & markedText into replaceAction
  50.     send replaceAction
  51.   end if
  52. end replace
  53.  
  54.  
  55. -- part contents for background part 1
  56. ----- text -----
  57.  
  58. where ReplaceWithString is the string to replace the Find What String. As with the first handler, you need double neutral quotation marks (") around the argument if it is more than one word. This handler uses the information in the global variable declared by the first handler to find the character positions for placing the new string. It then does the replacement. The reason there are two handlers is that this way it is possible to search for a particular string and check it (your own script could check the foundLine, for example). If it checks out to be the one that should be replaced, the replace handler can be then called to do the replacement.
  59.  
  60. To copy the scripts to your stack, click the button below, and its scripting dialog will appear containing the the two aforementioned scripts (below its own mouseUp handler).
  61.  
  62.